Skip to content

[YouTube] Extract client version from service worker data#1520

Open
FineFindus wants to merge 1 commit into
TeamNewPipe:devfrom
FineFindus:fix/yt-service-worker-data
Open

[YouTube] Extract client version from service worker data#1520
FineFindus wants to merge 1 commit into
TeamNewPipe:devfrom
FineFindus:fix/yt-service-worker-data

Conversation

@FineFindus

@FineFindus FineFindus commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Fixes extracting the web client version, by extracting the version from the service worker data (https://www.youtube.com/sw.js_data). This avoids the additional request, which is necessary after failing to extract the version, when falling back to extracting version from the search page.

Closes: #872

  • I carefully read the contribution guidelines and agree to them.
  • I have tested the API against NewPipe.
  • I agree to create a pull request for NewPipe as soon as possible to make it compatible with the changed API.

@sonarqubecloud

Copy link
Copy Markdown

@absurdlylongusername absurdlylongusername left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR @FineFindus

After reading #872 I don't think I see how this resolves it.

That issue mentions https://www.youtube.com/sw.js no longer containing something, but from what I see it still has the client version, so I presume it no longer has the API key and we used to get it from there.

The issue says it wants to find way to get both client version and API key, but your PR only gets client version from what I can see.

So given that I don't think this closes #872. Please correct me if I'm wrong.

Additionally, what is the benefit of getting client version from sw.js_data instead of sw.js?

Also:

  1. I believe this will need to update all of related YT mocks as it's calling a new endpoint that returns a new response
  2. Please add tests that prove that this works

@FineFindus

Copy link
Copy Markdown
Contributor Author

That issue mentions https://www.youtube.com/sw.js no longer containing something, but from what I see it still has the client version, so I presume it no longer has the API key and we used to get it from there.

It seems when logged in calling the URL returns different data. When logged out I only get

  self.addEventListener('install', event => {
    event.waitUntil(self.skipWaiting());
  });
  self.addEventListener('activate', event => {
    event.waitUntil(
      self.clients.claim().then(() => self.registration.unregister()));
  });

The issue says it wants to find way to get both client version and API key, but your PR only gets client version from what I can see.

API keys are not used anymore, see #1168.

Please add tests that prove that this works

Not quite sure what's the best way to test this, since the method is private and the public function that uses it still works, since it falls back to extracting the version from the HTML page?

@AudricV

AudricV commented Jun 30, 2026

Copy link
Copy Markdown
Member

The issue says it wants to find way to get both client version and API key, but your PR only gets client version from what I can see.

So given that I don't think this closes #872. Please correct me if I'm wrong.

It does. The InnerTube API doesn't require an API key for a few years now.

@absurdlylongusername

absurdlylongusername commented Jun 30, 2026

Copy link
Copy Markdown
Member

@FineFindus Ah okay my bad, I was logged in 🤦‍♂️. Thank you for this information

Not quite sure what's the best way to test this, since the method is private and the public function that uses it still works, since it falls back to extracting the version from the HTML page?

Okay I've looked at the surrounding code, I think not worth refactoring to be able to test this explicitly neither is it quick or straightforward to do so.

What we should have is a test specifically for getting client version that tests the contract of getting the client version, and tests each branch of the method, but that's prob too much for this PR.

Still need to update the mocks though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Find ways to get InnerTube's client version and API key of WEB and WEB_REMIX clients without using YouTube and YouTube's Music HTML pages

3 participants